package com.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import android.util.Log;

public class PlantInfoSmallDatabase  extends SQLiteOpenHelper {
	private static final String DATABASE_NAME = "plantsmall.db";
	private static final int DATABASE_VERSION = 1;

	// Table name
	public static final String TABLE = "plantsmall";

	// Columns
	public static final String PLANT_TYPE_ID = "planttype";
	public static final String SEASON = "season";
	public static final String TEMPERATURE = "temperature";
	public static final String HUMIDITY = "humidity";
	public static final String LIGHT_NEEDS = "lightneeds";
	public static final String SOIL = "soil";
	public static final String WATERING = "watering";
	public static final String FERTILIZER = "FERTILIZER";
	
	public PlantInfoSmallDatabase(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String sql = "create table " + TABLE + "( " + PLANT_TYPE_ID + " integer, "
				+ SEASON  + " text not null,"  + TEMPERATURE  + " text not null," + HUMIDITY + " integer, " 
				+ LIGHT_NEEDS + " integer, " + SOIL + " text not null, " + WATERING + " integer, " + FERTILIZER + " text not null" + ");";
		Log.d("EventsData", "onCreate: " + sql);
		db.execSQL(sql);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (oldVersion >= newVersion)
			return;

		String sql = null;
		if (oldVersion == 1) 
			sql = "alter table " + TABLE + " add note text;";
		if (oldVersion == 2)
			sql = "";

		Log.d("EventsData", "onUpgrade	: " + sql);
		if (sql != null)
			db.execSQL(sql);
	}

}